#ifndef BUFFER_H
#define BUFFER_H

// Buffers I/O of compiler
class Buffer {
private:
	char* inputBuffer;
	char* outputBuffer;

	int inputFile;
	int outputFile;
	int readFile;
	int writeFile;

	unsigned int inputIndex;
	unsigned int outputIndex;
	unsigned int fileIndex;

	bool buffer1IsAlreadyChanged;
	bool buffer2IsAlreadyChanged;
	bool finished;

	bool initInput();
	bool initOutput();

	bool reloadBuffer(int position);
	void flush();

public:
	Buffer();
	~Buffer();

	// initializes the Buffer with input- and output file
	bool init(const char* inputFile, const char* outputFile);

	// return one character from Buffer
	char getChar();
	// goes one step back in Buffer
	void ungetChar();

	// copies the last characters from buffer to given position
	void copyString(size_t lastChars, char* position);
	// puts the given string into output buffer
	// writes output buffer into specified output file
	void writeString(const char* printString);
};

#endif
